<?php include_component('questionaire', 'tabs') ?>

<?php use_stylesheets_for_form($form) ?>
<?php use_javascripts_for_form($form) ?>

<div class="sf_admin_form">
    <form action="<?php echo url_for('@admin_page?module=questionaire&action=questions&id=' . $qId) ?>" method="post">
        <?php echo $form->renderHiddenFields(true) ?>

        <?php if ($form->hasGlobalErrors()): ?>
            <?php echo $form->renderGlobalErrors() ?>
        <?php endif; ?>

        <table width="60%" style="float:left">
            <tfoot>
                <tr>
                    <td colspan="2">
                        <input class="formSubmit" type="submit" name="Save" value="<?php echo __('Save') ?>" />
                    </td>
                </tr>
            </tfoot>
            <tr>
                <td>
                    <fieldset>
                        <legend class="formLabel"><?php echo __('Questions') ?></legend>
                        <table>
                            <?php foreach ($form['questions'] as $index => $subform): ?>
                                <tr>
                                    <td style="width:80px;"><?php echo $subform['name']->renderLabel('Question ' . ($index + 1), array('class' => 'formLabel')) ?> </td>
                                    <td colspan="5"><?php echo $subform['name']->render(array('class' => 'formInput', 'style' => 'width:500px;')) ?> </td>
                                    <td><?php echo $subform['name']->renderError() ?> </td>
                                    <td><?php echo $subform['answer_type']->render(array('class' => 'formInput', 'style' => 'width:auto;')) ?> </td>
                                    <td>&nbsp;</td>
                                    <td><?php echo $subform['required']->renderLabel('Required', array('class' => 'formLabel', 'style' => 'width:auto;')) ?> </td>
                                    <td><?php echo $subform['required']->render(array('class' => 'formInput', 'style' => 'width:auto;')) ?> </td>
                                    <?php if ($index + 1 != count($form['questions'])): ?>
                                        <td style="width:30px;">&nbsp;</td>
                                        <td>
                                            <input id="<?php echo $subform['id']->getValue() ?>" class="formSubmit question_delete" type="submit" name="delete" value="<?php echo __('Delete') ?>" />
                                        </td>
                                    <?php endif; ?>
                                </tr>
                            <?php endforeach; ?>
                        </table>
                    </fieldset>
                </td>
            </tr>
        </table>
    </form>
</div>

<?php include_component('questionaire', 'footerTabs') ?>

<script type="text/javascript">
    $('.question_delete').click(function () {
        $.get('<?php echo url_for('@admin_page?module=questionaire&action=deleteQuestion&id=') ?>' + $(this).attr('id'), function(data) {
            window.location.href = '<?php echo url_for('@admin_page?module=questionaire&action=questions&id=' . $qId) ?>';
        });
       
        return false;
    });
</script>

